package person.xjl.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import person.xjl.dao.StudentMapper;
import person.xjl.domain.Student;
import person.xjl.service.StudentService;

import java.util.List;
//Spring 容器创建一个service类型的Bean,如果你不命名的话，类的首写字母小写studentServiceImpl
//为Controller层调用service对象服务的
//Bean有四种类型，@Controller,@Service,@Repository,@Bean
@Service
public class StudentServiceImpl implements StudentService {
    //自动注入Spring 容器创建的对象，对象的名字是 类或者接口的首写字母小写
    //studentMapper熟悉的名字是被Spring容器固定了，不能乱写
@Autowired
private StudentMapper studentMapper;
//调用dao层的studentMapper对象的list方法，显示所有学生信息
    @Override
    public List<Student> list() {
        return studentMapper.list();
    }
    //调用dao层的studentMapper对象的insert方法，添加新学生
    @Override
    public int add(Student student) {
        return studentMapper.insert(student);
    }

    @Override
    public int delete(int id) {
        return studentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Student find(int id) {
        return studentMapper.selectByPrimaryKey(id);
    }

    @Override
    public int edit(Student newStudent) {
        return studentMapper.updateByPrimaryKey(newStudent);
    }

    @Override
    public Student login(String name, String password) {
        return studentMapper.login(name,password);
    }


}
